package com.simple.car.loader.server.listener;

import android.view.GestureDetector;
import android.view.MotionEvent;
import android.widget.Toast;

import com.simple.car.loader.server.annotation.Function;
import com.simple.car.loader.server.annotation.Loader;
import com.simple.car.loader.server.entity.vo.RunningInfoVo;
import com.simple.car.loader.server.tools.LocalTool;

import java.util.Date;

@Function
public class TaskClickListener extends GestureDetector.SimpleOnGestureListener {

    @Loader
    private LocalTool localTool;

    private RecorderListener recorderListener;

    @Override
    public boolean onDoubleTap(MotionEvent e) {
        dangerousActions();
        return super.onDoubleTap(e);
    }

    @Override
    public boolean onSingleTapConfirmed(MotionEvent e) {
        warningAction();
        return super.onSingleTapConfirmed(e);
    }

    private void warningAction() {
        action("warning");
    }

    private void dangerousActions() {
        action("dangerous");
    }

    private void action(String action) {
        RunningInfoVo runningVo = localTool.getRunningVo();
        runningVo.setLevel(action);
        runningVo.setCreateTime(new Date());
        Toast.makeText(localTool.getContext(), action.concat(":").concat(runningVo.getPosition()), Toast.LENGTH_LONG).show();
    }

    @Override
    public boolean onDown(MotionEvent e) {
        return true;
    }

    public RecorderListener getRecorderListener() {
        return recorderListener;
    }

    public void setRecorderListener(RecorderListener recorderListener) {
        this.recorderListener = recorderListener;
    }

    public interface RecorderListener {

        void record(int count);
    }
}
